package com.oocl.main;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;

import com.oocl.thread.FileDownloader;

public class MainProcessor {
	
	 
    public static void main(String[] args) {
    	InputStream in = null;
		RandomAccessFile rfread = null;
		RandomAccessFile rfwrite = null;
    	try {
			 in = new FileInputStream("test.jpg");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			 rfread = new RandomAccessFile("test.jpg","rw");
			 rfwrite = new RandomAccessFile("dowload/copydata.jpg","rw");//文件下载到本项目根目录下的download文件夹中
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			rfwrite.setLength(in.available());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			new FileDownloader(0,in.available()/5,rfread,rfwrite).start(); 
		    new FileDownloader(in.available()/5,in.available()/5,rfread,rfwrite).start();
		    new FileDownloader(in.available()/5*2,in.available()/5,rfread,rfwrite).start();
		    new FileDownloader(in.available()/5*3,in.available()/5,rfread,rfwrite).start();
		    new FileDownloader(in.available()/5*4,in.available()/5+in.available()%5,rfread,rfwrite).start();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//		try {  
//			Thread.sleep(10000);
//        	rfread.close();  
//        	rfwrite.close();
//        } catch (Exception e) {  
//        }  
		
	}
    
}
